package com.hqyj.controller;


import com.hqyj.pojo.SelectAll;
import com.hqyj.pojo.User;
import com.hqyj.pojo.UserVO;
import com.hqyj.service.UserService;
import com.hqyj.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/register")
    public Map<String,Object> register(String uAccount ,String uPassword , String uPhone ,String code) {

        return userService.register(uAccount,uPassword,uPhone,code);
    }

    @RequestMapping("/getCode")
    public Map<String,Object> getCode(String uPhone){

        return userService.getCode(uPhone);
    }

    @RequestMapping("/checkAccount")
    public Map<String,Object> checkPhone(String uAccount){
        return userService.checkAccount(uAccount);
    }

    @RequestMapping("/login")
    public Map<String,Object> login(String uAccount , String uPassword ,HttpServletRequest request){

        return userService.login(uAccount,uPassword,request);
    }

    //分页
    @RequestMapping("/selectAll")
    @ResponseBody
    public Map<String,Object> selectAll(int pageNum,int pageSize,String uName,String departmentName){
        return userService.selectAll(pageNum,pageSize,uName,departmentName);
    }

    //信息回显
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(int id){
        return userService.update(id);
    }

    //信息修改
    @RequestMapping("/updateUser")
    @ResponseBody
    public Map<String,Object> updateUser(User user){
        return userService.updateUser(user);
    }

    //删除用户
    @RequestMapping("/deleteUser")
    @ResponseBody
    public Map<String,Object> deleteUser(int id){
        return userService.deleteUser(id);
    }


    @RequestMapping("/logout")
    @ResponseBody
    public Map<String,Object> logout(String uAccount){
        return userService.logout(uAccount);
    }

}
